/**
 * @package JV Accordion Ajax module for Joomla! 1.6
 * @author http://www.zootemplate.com
 * @copyright (C) 2011- ZooTemplate.Com
 * @license PHP files are GNU/GPL
**/ 
var k				= 0;
var loaded			= Array();
var JVAccordionAjax = new Class({
	initialize: function(toggler, element, ajaxUrl, mod_id, jvStyle, collapsible){
		var articleClassId 	= element.getProperty('id');
		articleId 			= articleClassId.split('_')[1];
		
		if(loaded.indexOf(articleId) == -1)
		{						
			/*Set Loading Image*/
			if(jvStyle == 'jv_default_accordion')
			{
				toggler.setStyle('padding-left','0px');
				var children 		= toggler.innerHTML;
				var oldTitle		= toggler.innerHTML;
				var wrapDiv 		= "<div class='ajax-loading-accordion'>"+children+"</div>";                                     
				toggler.innerHTML 	= wrapDiv; 
			}
			else if(jvStyle == 'jv_button_accordion')
			{
				var oldTitle		= toggler.innerHTML;
				var children 		= toggler.innerHTML;
				var wrapDiv			= "<div class='ajax-loading-accordion'>"+children+"</div>";
				toggler.innerHTML 	= wrapDiv; 
			}
			else
			{
				var oldTitle		= toggler.innerHTML;
				toggler.getParent().getParent().addClass('ajax-loading-accordion');
			} 
			/*End*/
								
			var request 	= new Request.JSON({url:ajaxUrl, onSuccess: function(jsonObj){
				
				if(jvStyle == 'jv_default_accordion')
				{								
					toggler.empty();
					toggler.setStyle('padding-left','10px');                                          
					toggler.innerHTML = oldTitle;
				}
				else if(jvStyle =='jv_button_accordion')
				{
					toggler.empty();
					toggler.innerHTML = oldTitle;
				}
				else
				{
					toggler.getParent().getParent().removeClass('ajax-loading-accordion');
				}
				loaded[k]		= articleId;
				k++;
				element.innerHTML = jsonObj.articleContent;
				collapsible.toggle();
			}}).get({'moduleId' : mod_id, 'articleId' : articleId});
		}
	}
});